const fs = require('fs-extra')
const handlebars = require('handlebars')
const { resolve } = require('path')

const getTplFilePath = () => ({
  // 组件库npm打包配置文件
  npm: {
    from: '../packages/package.json.tpl',
    to: `../dist/package.json`
  },
})

const compFilesTplReplacer = () => {
  const filePaths = getTplFilePath()
  Object.keys(filePaths).forEach(key => {
    const fileTpl = fs.readFileSync(resolve(__dirname, filePaths[key].from), 'utf-8')
    const fileContent = handlebars.compile(fileTpl)()
    fs.outputFile(resolve(__dirname, filePaths[key].to), fileContent, err => {
      if (err) console.log(err)
    })
  })
}

compFilesTplReplacer()
// const child_process = require('child_process');

// const copyDir = (src, dist) => {
//   // child_process.spawn('cp', ['-r', , src, dist]);  // linux系统指令
//   child_process.spawn('cmd.exe', ['/c','\.\\script\\copyFile.bat']); // windiows系统指令
  
// };

// copyDir('./packages/package.json', './dist/');
